<!DOCTYPE html>
<html lang="zh-cn">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
  <meta name="renderer" content="webkit">
  <title></title>
  <link rel="stylesheet" href="__CSS__/pintuer.css?v={$src_version}">
  <link rel="stylesheet" href="__CSS__/admin.css?v={$src_version}">
  <link rel="stylesheet" href="__CSS__/responsive.css?v={$src_version}">
  <script src="__JS__/jquery-3.2.1.min.js?v={$src_version}"></script>
  <script src="__JS__/pintuer.js?v={$src_version}"></script>
  <script src="__JS__/jquery.nicescroll.js"></script>
  <script src="__PUBLIC__/layer.js?v={$src_version}"></script>
  <script src="__JS__/ming.js?v={$src_version}"></script>
  <script src="__JS__/ifram_scroll.js?v={$src_version}"></script>
  <script src="__JS__/responsive.js?v={$src_version}"></script>
</head>

<body>

  <div class="panel admin-panel ">
    <form method="post" class="form-x" id="frm" action="">
      <div class="panel-head" id="add">
        <strong>
          <span class="icon-pencil-square-o"></span>一般积分操作</strong>
      </div>
      <div class="body-content">
        <div class="form-group">
          <div class="label">
            <label>
              <strong style="color:#f00;">*</strong>项目类型</label>
          </div>
          <div class="field">
            <select class="input w50" name="opt" id="opt">
              <option value="0" data="0">请选择</option>
              <option value="+" data="+">加分项目</option>
              <option value="-" data="-">减分项目</option>
            </select>
          </div>
        </div>
        <div class="form-group">
          <div class="label">
            <label>
              <strong style="color:#f00;">*</strong>项目名称</label>
          </div>
          <div class="field">
              <select name="pid" class="input w50" id="pid" id="pid">
                  <option value="0" data="0">项目名称</option>
                  <volist name="pid" id="v">
                    <option value="{$v.pid}" data="{$v.pid}">
                      {$v.pname}
                    </option>
                  </volist>
    
                </select>
          </div>
        </div>
        <div class="form-group">
          <div class="label">
            <label>
              <strong style="color:#f00;">*</strong>积分数量</label>
          </div>
          <div class="field">
            <input type="text" class="input w50" readonly style="cursor:pointer;" id="point" name="point" maxlength="11" />
          </div>
        </div>

        <div class="form-group">
          <div class="label">
            <label>
              <strong style="color:#f00">*</strong>备注</label>
          </div>
          <div class="field">
            <input type="text" class="input w50" style="cursor: pointer;" id="note" name="note" maxlength="50" />
          </div>
        </div>

        <div class="form-group">
          <div class="label">
            <label></label>
          </div>
          <div class="field">
            <input type="hidden" name="id" id="id" value="{$user.uid}" />
            <input type="hidden" name="act" value="add" />
            <div class="button-group">
              <a class="button bg-main" href="javascript:;" id="sbt">
                <span class="icon-check-square-o"></span> 提交
              </a>
              <a class="button border-main" href="javascript:history.go(-1)">
                <span class="icon-mail-reply"></span> 返回</a>
            </div>
          </div>
        </div>

      </div>
    </form>
  </div>


  <script type="text/javascript">
    $(function () {

      //点击获取项目     
      $('#opt').change(function () {
        var opt = $(this).children('option:selected').attr('data'); //jquery 写法
        if (opt == '0' || opt == '') {
          layer.msg('请选择项目类型', { icon: 2 });

          $('#pid').empty();//首先清空select现在有的内容

          $("#pid").append("<option selected='selected'  value='0'>项目名称</option>");

          $('#point').val('');

          return false;

        }
        $.ajax({

          type: 'post',

          url: '{:U("User/get_project")}',

          data: { opt: opt },

          dataType: 'json',

          success: function (res) {

            if (res.code == '1') {

              $('#pid').empty();//首先清空select现在有的内容

              $("#pid").append("<option selected='selected'  data='0' value='0'>项目名称</option>");

              for (var i = 0; i < res.msg.length; i++) {

                $("#pid").append("<option  data=" + res.msg[i]['pid'] + "  value=" + res.msg[i]['pid'] + ">" + res.msg[i]['pname'] + "</option>");
              }

            }
            else {
              $('#pid').empty();//首先清空select现在有的内容

              $("#pid").append("<option selected='selected'  value='0'>项目名称</option>");

            }
            $('#point').val('');
          }
        });

      });
      //点击获取积分     
      $('#pid').change(function () {
        var pid = $(this).children('option:selected').attr('data'); //jquery 写法

        $.ajax({

          type: 'post',

          url: '{:U("User/get_point")}',

          data: { pid: pid },

          dataType: 'json',

          success: function (res) {

            if (res.code == '1') {

              $('#point').val(res.msg);

            }
            else {
              $('#point').val('');
            }

          }
        });

      });

      //--------------------------------------------------------------------------------------------------------------------------------// 
      $('#sbt').click(function () {
        var pid = $.trim($('#pid').val());

        if (pid == '0' || pid == '') {
          layer.msg('请选择项目', { icon: 2 });
          return false;

        }
        // console.log(decodeURIComponent($('#frm').serialize()));
        var re = $.mAjax("{:U('User/handle_point')}",decodeURIComponent($('#frm').serialize()) , 'json', 'sbt', '提交中...', '<span class="icon-check-square-o"></span> 提交');
      });




    });


  </script>
</body>

</html>